import time

from appium.webdriver.common.appiumby import  By


def app_buy_now(driver):
    time.sleep(2)
    # 点击商品详情
    driver.find_element(by=By.ID, value="com.tpshop.malls:id/product_pic_img").click()
    time.sleep(2)
    # 点击立即购买
    driver.find_element(by=By.ID, value="com.tpshop.malls:id/promptly_buy_tv").click()
    time.sleep(2)
    # 点击确定
    driver.find_element(by=By.ID, value="com.tpshop.malls:id/confirm_tv").click()
    # 选择收货地址
    time.sleep(2)
    driver.find_element(by=By.ID, value="com.tpshop.malls:id/order_address_tv").click()
    time.sleep(2)
    driver.find_element(by=By.ID, value="com.tpshop.malls:id/address_mobile_tv").click()
    # 点击立即购买
    time.sleep(2)
    driver.find_element(by=By.ID, value="com.tpshop.malls:id/submit_tv").click()


def pay_now_page(driver):
    time.sleep(1)
    ele = driver.find_element(by=By.ID, value="com.tpshop.malls:id/balance_check").is_selected()

    time.sleep(1)

    if not ele:
        # 点击立即支付
        time.sleep(1)
        driver.find_element(by=By.ID, value="com.tpshop.malls:id/pay_btn").click()

        driver.find_element(by=By.ID, value='com.tpshop.malls:id/pwd_et').send_keys('lhl123456')

        driver.find_element(by=By.ID, value='com.tpshop.malls:id/sure_tv').click()